package com.hnichr.crm.common.business.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.hnichr.crm.common.customer.entity.CrmCustomer;
import com.hnichr.crm.common.product.entity.CrmProduct;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 商机对象 crm_business
 *
 * @author Cheng
 * @date 2022-11-24
 */
@Data
@Entity
@Table(name = "crm_business")
@Schema(description = "商机表")
@EqualsAndHashCode(callSuper = false)
public class CrmBusiness extends BaseEntity {

    /**
     * id
     */
    @Id
    @Generator
    @Schema(description = "id")
    @Column(name = "id", length = 64)
    private String id;
    /**
     * 商机状态组
     */
    @Schema(description = "商机状态组")
    @Column(name = "type_id", length = 64)
    private String typeId;
    /**
     * 销售阶段
     */
    @Schema(description = "销售阶段")
    @Column(name = "status_id", length = 64)
    @Dict(dicCode = "business_status")
    private String statusId;
    /**
     * 下次联系时间
     */
    @Schema(description = "下次联系时间")
    @Column(name = "next_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date nextTime;
    /**
     * 上一次联系内容
     */
    @Schema(description = "上一次联系内容")
    @Column(name = "last_content", length = 1024)
    private String lastContent;
    /**
     * 最新活动记录时间
     */
    @Schema(description = "最新活动记录时间")
    @Column(name = "last_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastTime;
    /**
     * 客户ID
     */
    @Schema(description = "客户ID")
    @Column(name = "customer_id", length = 64)
    @Dict(dicEntity = CrmCustomer.class, dicCode = "id", dicText = "customerName")
    private String customerId;

    @ManyToOne()
    @JoinColumn(name = "customer_id", referencedColumnName = "id",insertable = false, updatable = false)
    private CrmCustomer crmCustomer;

    /**
     * 预计成交日期
     */
    @Schema(description = "预计成交日期")
    @Column(name = "deal_date")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date dealDate;
    /**
     * 商机名称
     */
    @Schema(description = "商机名称")
    @Column(name = "business_name", length = 50)
    private String businessName;
    /**
     * 商机金额
     */
    @Schema(description = "商机金额")
    @Column(name = "money")
    private BigDecimal money;
    /**
     * 整单折扣
     */
    @Schema(description = "整单折扣")
    @Column(name = "discount_rate")
    private BigDecimal discountRate;
    /**
     * 产品总金额
     */
    @Schema(description = "产品总金额")
    @Column(name = "total_price")
    private BigDecimal totalPrice;
    /**
     * 备注
     */
    @Schema(description = "备注")
    @Column(name = "remark", length = 500)
    private String remark;
    /**
     * 负责人ID
     */
    @Schema(description = "负责人ID")
    @Column(name = "owner_user_id", length = 64)
    @Dict(dicEntity = User.class, dicCode = "username", dicText = "nickname")
    private String ownerUserId;
    /**
     * 批次 比如附件批次
     */
    @Schema(description = "批次 比如附件批次")
    @Column(name = "batch_id", length = 64)
    private String batchId;
    /**
     * 只读权限
     */
    @Schema(description = "只读权限")
    @Column(name = "ro_user_id", length = 64)
    private String roUserId;
    /**
     * 读写权限
     */
    @Schema(description = "读写权限")
    @Column(name = "rw_user_id", length = 64)
    private String rwUserId;
    /**
     * 1赢单2输单3无效
     */
    @Schema(description = "1赢单2输单3无效")
    @Column(name = "is_end")
    private Integer isEnd;
    /**
     * statusRemark
     */
    @Schema(description = "statusRemark")
    @Column(name = "status_remark", length = 500)
    private String statusRemark;
    /**
     * 项目ID
     */
    @Schema(description = "项目ID")
    @Column(name = "product_id")
    @Dict(dicEntity = CrmProduct.class, dicCode = "id", dicText = "name")
    private String productId;
    /**
     * 消息来源
     */
    @Schema(description = "消息来源")
    @Column(name = "source", length = 10)
    @Dict(dicCode = "news_source")
    private String source;
    /**
     * 有无合同
     */
    @Schema(description = "有无合同")
    @Column(name = "is_contract", length = 10)
    @Dict(dicCode = "is_contract")
    private String isContract;
    /**
     * 跟进公司
     */
    @Schema(description = "跟进公司")
    @Column(name = "company_name", length = 255)
    @Dict(dicCode = "company")
    private String companyName;
    /**
     * 跟进部门
     */
    @Schema(description = "跟进部门")
    @Column(name = "dept_id")
    @Dict(dicEntity = Dept.class, dicCode = "deptCode", dicText = "deptName")
    private String deptId;
    /**
     * 跟进部门名称
     */
    @Schema(description = "跟进部门名称")
    @Column(name = "dept_name", length = 255)
    private String deptName;
    /**
     * 客户名称
     */
    @Schema(description = "客户名称")
    @Column(name = "customer_name", length = 255)
    private String customerName;
    /**
     * 项目名称
     */
    @Schema(description = "项目名称")
    @Column(name = "product_name", length = 255)
    private String productName;

    @Schema(description = "文件id")
    @Column(name = "file_id", length = 512)
    private String fileList;

    @Transient
    private String fileNames;
}
